getmyData('resourcesData', resourcesData)
var benDiDang = getmyData('resourcesData')
if (benDiDang == null) {
    setmyData('resourcesData', resourcesData)
    benDiDang = getmyData('resourcesData')
}
// 当前页
let myPageUl_num = 1

// tbody渲染内容
function showTable_two(data) {
    myTbody_two.innerHTML = ""
    data.forEach(item => {
        myTbody_two.innerHTML += ` 
                        <div class="myTbody_two_D">
                              <div class="myTbody_two_left">
                                  <img src="${item.resourcesImg}" alt="">
                              </div>
                              <div class="myTbody_two_right">
                                  <h4>${item.resourcesHt}</h4>
                                  <p> <span>阅读3000</span> <span>评论</span> <span>98</span>  <span>转发128</span> <p>
                                  <div class="myTbody_two_right_topping">置顶</div>
                                  <div class="myTbody_two_right_abr"> 
                                      <span> <span class="iconfont icon-ren"></span>${item.resourcesUser}</span>  <span>2020-7-11 15:00</span>
                                      <span class="myTbody_two_right_cancel">取消置顶</span>
                                      <span class="myTbody_two_delt" onclick="myTbodyTwoDlet(${item.resourcesId})">删除</span> 
                                      
                                      <span class='myTbody_two_edit' onclick = 'myTbodyTwoEdit(${JSON.stringify(item)})'>编辑</span> 
                                  </div>
                              </div>
                              </div>
                        </div> 
                             `
    });
}

let zxMaxPage

// 限制每页数据
function limitPage(data) {
    // 当前页
    let goPage = (data - 1) * 5
    let stopPage = benDiDang.slice(goPage, goPage + 5)
    showTable_two(stopPage)
}
limitPage(myPageUl_num)


// 动态输出页码
function GetPageNumber(data) {
    let myPageUl = document.getElementById('myPageUl')
    //共多少记录
    let gongDuoShao = `<li class="myPageUlToTal">共 <span class="myPageUlToTal_shuzi"> 0 </span> 条记录 第<span class="myPageUlToTal_ji"> 1 </span> / <span class="myPageUlToTal_yigong"> 0 <span> 页 </li>`

    // 页码
    zxMaxPage = Math.ceil(data.length / 5)
    // 上一页
    let zpre = `<li class="myPageUlPress_shang iconfont icon-xiangzuo"></li>`
    let zstr = ''
    // 页码数循环添加页码
    for (let i = 1; i <= zxMaxPage; i++) {
        zstr += `<li class="myPageUlPress"   data-num_two='${i}'>${i}</li>`
    }

    // 字符串拼接  下一页
    zstr = gongDuoShao + zpre + zstr + `<li class="myPageUlPress_xia iconfont icon-xiangyou1"></li>`
    myPageUl.innerHTML = zstr

    two_dangqianye()
    twoYiGongDuoShao()
}
GetPageNumber(benDiDang)


// 点击几到几页
$('#myPageUl').on('click', '.myPageUlPress', function () {
    myPageUl_num = $(this).attr('data-num_two')
    limitPage(myPageUl_num)
    // $('.myPageUlToTal_ji').html(myPageUl_num)
    two_dangqianye()
})


// 给上一页绑定点击事件
$('#myPageUl').on('click', '.myPageUlPress_shang ', function () {
    if (myPageUl_num != 1) {
        myPageUl_num--
        limitPage(myPageUl_num)
    }
    two_dangqianye()
    // $('.myPageUlToTal_ji').html(myPageUl_num)

})

function two_dangqianye() {
    $('.myPageUlToTal_ji').html(myPageUl_num)
}
two_dangqianye()


// 下一页绑定点击事件
$('#myPageUl').on('click', '.myPageUlPress_xia', function () {
    if (myPageUl_num < zxMaxPage) {
        myPageUl_num++
        limitPage(myPageUl_num)
    }
    // $('.myPageUlToTal_ji').html(myPageUl_num)
    two_dangqianye()
})

// 页码显示共多少条记录
function duoShaoYe() {
    $('.myPageUlToTal_shuzi').html(benDiDang.length)
}
duoShaoYe()

// 一共多少也
function twoYiGongDuoShao() {
    $('.myPageUlToTal_yigong').html(Math.ceil(benDiDang.length / 5))
}
twoYiGongDuoShao()

// 点击删除
function myTbodyTwoDlet(data) {
    for (let i = 0; i < benDiDang.length; i++) {
        if (data == benDiDang[i].resourcesId) {
            benDiDang.splice(i, 1)
            break;
        }
    }
    showTable_two(benDiDang)
    limitPage(myPageUl_num)
    setmyData('resourcesData', benDiDang)
    duoShaoYe()
    twoYiGongDuoShao()

}


// 编辑
function myTbodyTwoEdit(data) {
    $('.informationList_bianji').css({
        display: 'block',
    })

    $('.whites').css({
        background: 'rgba(127,128,129,0.7)',
    })

    $('#informationList').css({
        zIndex: '-1',
    })
    $('#columnList').css({
        zIndex: '-1',
    })

    $('#one_heise').css({
        background: 'rgba(127,128,129,0.7)',
    })

    let informationList_bianji_center_1inpt = document.getElementById('informationList_bianji_center_1inpt')
    let informationList_bianji_center_2inpt = document.getElementById('informationList_bianji_center_2inpt')
    let informationList_bianji_center_4_1 = document.getElementById('informationList_bianji_center_4_1')
    let informationList_bianji_center_2img = document.getAnimations('informationList_bianji_center_2img')
    let yinshenId = document.getElementById('yinshenId')


    informationList_bianji_center_1inpt.value = data.resourcesHt
    informationList_bianji_center_4_1.value = data.resourcesUser
    yinshenId.value = data.resourcesId
    informationList_bianji_center_2img.src = data.resourcesImg
}

// 编辑取消
function bianJiQuXiao() {
    $('.informationList_bianji').css({
        display: 'none',
    })

    $('.whites').css({
        background: 'rgb(240, 242, 245)',
    })

    $('#informationList').css({
        zIndex: '0',
    })

    $('#columnList').css({
        zIndex: '0',
    })

    $('#one_heise').css({
        background: 'rgb(240, 242, 245)',
    })
    informationList_bianji_center_1inpt.value = ""
    informationList_bianji_center_4_1.value = ""

}


// 改变图片
let table_edit3_2 = document.getElementById('table_edit3_2')
function newfile(obj) {
    var reader = new FileReader();	// 实例化一个FileReader对象，用于读取文件
    reader.onload = function (evt) {
        table_edit3_2.src = evt.target.result;
    }
    reader.readAsDataURL(obj.files[0]);
}


// 编辑确认
$('.informationList_bianji_center').on('click', '.informationList_bianji_center_6baocun', function () {
    let informationList_bianji_center_1inpt = document.getElementById('informationList_bianji_center_1inpt')
    let informationList_bianji_center_4_1 = document.getElementById('informationList_bianji_center_4_1')
    let table_edit3_2 = document.getElementById('table_edit3_2')

    // 作者
    for (let i = 0; i < benDiDang.length; i++) {
        if (benDiDang[i].resourcesId == parseInt(yinshenId.value)) {
            benDiDang[i].resourcesHt = informationList_bianji_center_1inpt.value
            benDiDang[i].resourcesUser = informationList_bianji_center_4_1.value
            benDiDang[i].resourcesImg = table_edit3_2.src
            break;
        }
    }

    setmyData('resourcesData', benDiDang)
    limitPage(myPageUl_num)
    GetPageNumber(benDiDang)
    bianJiQuXiao()
    duoShaoYe()
})


// 添加资讯
function addInformationList() {
    $('.informationList_addTo').css({
        display: 'block',
    })

    $('.whites').css({
        background: 'rgba(127,128,129,0.7)',
    })

    $('#informationList').css({
        zIndex: '-1',
    })

    $('#columnList').css({
        zIndex: '-1',
    })

    $('#one_heise').css({
        background: 'rgba(127,128,129,0.7)',
    })
}

// 添加资讯取消
function addToQuXiao() {
    $('.informationList_addTo').css({
        display: 'none',
    })

    $('.whites').css({
        background: 'rgb(240, 242, 245)',
    })

    $('#informationList').css({
        zIndex: '0',
    })

    $('#columnList').css({
        zIndex: '0',
    })
    $('#one_heise').css({
        background: 'rgb(240, 242, 245)',
    })
}


// 新填图片
// let informationList_addTo_center_2img = document.getElementById('informationList_addTo_center_2img')
// function newfile(obj) {
//     var readerXz = new FileReader();	// 实例化一个FileReader对象，用于读取文件
//     readerXz.onload = function (evt) {
//         informationList_addTo_center_2img.src = evt.target.result;
//     }
//     readerXz.readAsDataURL(obj.files[0]);
// }


// 添加资讯保存
function informationListSaving() {
    let addColumn_1_inp = $('#informationList_addTo_center_1inpt').val()
    let informationList_addTo_center_4_1 = $('#informationList_addTo_center_4_1').val()
    let informationList_addTo_center_2inpt = document.getElementById('informationList_addTo_center_2inpt')
    let informationList_addTo_center_2img = document.getElementById('informationList_addTo_center_2img')
    let zxcvb = new XinDuiXiang(addColumn_1_inp, informationList_addTo_center_4_1, informationList_addTo_center_2img.src)
    function XinDuiXiang(resourcesHt, resourcesUser, resourcesImg) {
        this.resourcesHt = resourcesHt
        this.resourcesUser = resourcesUser
        this.resourcesImg = resourcesImg
    }

    benDiDang.push(zxcvb)
    setmyData('resourcesData', benDiDang)
    addToQuXiao()
    GetPageNumber(benDiDang)
    bianJiQuXiao()
    duoShaoYe()
}





// 重置
function resetQueryT() {
    $('#columnList_bottom_sousuo').val("")
    $('#columnList_bottom_xiala_01').val('1')
    $('#columnList_bottom_xiala_02').val('1')
    myPageUl_num = 1
    limitPage(1)
    GetPageNumber(benDiDang)
    setmyData('resourcesData', benDiDang)
    duoShaoYe()
    twoYiGongDuoShao()
    two_dangqianye()
}

let rgbT
let xinDiDan
// 查询
function inquiryAndConsultation() {
    for (var i = 0; i < benDiDang.length; i++) {
        if ($('#columnList_bottom_sousuo').val() == benDiDang[i].resourcesHt) {
            rgbT = benDiDang[i]
            xinDiDan = []
            xinDiDan.push(rgbT)
            showTable_two(xinDiDan)
            break;
        }
    }
    setmyData('resourcesData', benDiDang)
    addToQuXiao()
    bianJiQuXiao()
    duoShaoYe()
}

let flagTwo
// 置顶
$('.myTbody_two_right_topping').click(function () {
    $(this).css({ display: 'none' })
    $(this).next().children('.myTbody_two_right_cancel').css({
        display: 'block'
    })
})
// $(this).parents('.myTbody_two_D').each(function () {
// for (let i = 0; i < benDiDang.length; i++) {
// if ($(this).parents('.myTbody_two_D').index() != 0) {
//     // let dangQianSj = benDiDang[i]
//     // console.log(benDiDang);
//     benDiDang.unshift(benDiDang.splice($(this).parents('.myTbody_two_D').index() != 0), 1)[0]
//     // break
// }
// // }
// // })
// console.log($(this).parents('.myTbody_two_D').index());





// 取消置顶
$('.myTbody_two_right').on('click', '.myTbody_two_right_cancel', function () {
    $(this).css({
        display: 'none'
    })

    $(this).parent().prev('.myTbody_two_right_topping').css({
        display: 'block'
    })
    console.log($(this).parent().prev('.myTbody_two_right_topping'));
})